package org.yinweichen.llm_dataset_backend.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.yinweichen.llm_dataset_backend.DTO.CategoryUpdateDTO;
import org.yinweichen.llm_dataset_backend.service.StandardQuestionService;

import java.util.List;

@RestController
@RequestMapping("/api/categories")
public class CategoryController {

    private final StandardQuestionService standardQuestionService;

    public CategoryController(StandardQuestionService standardQuestionService) {
        this.standardQuestionService = standardQuestionService;
    }

    @GetMapping("/{version}")
    public ResponseEntity<List<String>> getAllCategories(@PathVariable String version) {
        List<String> categories = standardQuestionService.getAllCategories(version);
        return ResponseEntity.ok(categories);
    }

    @PostMapping("/set")
    public ResponseEntity<Void> setQuestionCategory(@RequestBody CategoryUpdateDTO dto) {
        standardQuestionService.setQuestionCategory(dto.questionId(), dto.version(), dto.category());
        return ResponseEntity.noContent().build();
    }
}